<!DOCTYPE html>
<html>
<head>
    <meta charset="UTF-8">
    <title>leaflet 建筑立体效果</title>
    <link rel="stylesheet" href="http://cdn.bootcss.com/leaflet/1.0.3/leaflet.css">
    <script type="text/javascript" src="http://cdn.bootcss.com/leaflet/1.0.3/leaflet.js"></script>
    <script type="text/javascript" src="http://apps.bdimg.com/libs/jquery/2.1.1/jquery.min.js"></script>
    <script type="text/javascript" src="http://iclient.supermapol.com/libs/osmbuildings/OSMBuildings-Leaflet.js"></script>
</head>
<body style=" margin: 0;overflow: hidden;background: #fff;width: 100%;height:100%;position: absolute;top: 0;">
<div id="map" style="margin:0 auto;width: 100%;height: 100%"></div>
<script>
    var map = new L.Map('map', {
        center: [39.916, 116.450],
        zoom: 16
    });

    L.tileLayer('https://{s}.tiles.mapbox.com/v3/osmbuildings.kbpalbpk/{z}/{x}/{y}.png', {
        attribution: 'Imagery © <a href="http://mapbox.com">Mapbox</a>'
    }).addTo(map);

    loadData();

    function loadData() {
        var data;
        $.get('../data/buildings.json', function (geojson) {
            data = geojson;
            new OSMBuildings(map)
                .date(new Date(2017, 5, 15, 17, 30))
                .set(geojson)
                .click(bindPopup);
        });


        function bindPopup(evt) {
            var name = getFeatureNameById(evt.feature);
            if (name) {
                L.popup().setContent(name).setLatLng(L.latLng(evt.lat, evt.lon)).openOn(map);
            }
        }

        function getFeatureNameById(id) {
            if (!data || !id) {
                return null;
            }
            var features = data.features;
            for (var i = 0; i < features.length; i++) {
                if (features[i].properties.id === id) {
                    return features[i].properties.name;
                }
            }
        }
    }
</script>
</body>
</html>